package com.ninth_group.dao.Impl;

import com.ninth_group.function.TriFunction;
import com.ninth_group.po.TFHData;
import com.ninth_group.utils.QueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 24小时天气数据访问接口实现类
 */
@Repository
public class TFHDataDaoImplBackup{
    @Autowired
    private QueryUtil queryUtil;

    private static final String TABLE_NAME = "hourly_realtime_data";

    /**
     * 根据城市和省份名称获取城市24小时天气信息
     * @param cityIds 城市id集合
     * @return 城市基本信息
     */
    public List<TFHData> getCityTwentyForHoursData(List<String> cityIds) {
        return getCityTwentyForHoursData(
                TABLE_NAME,
                cityIds,
                TFHData.class,
                null,
                QueryUtil::getCityByIdToList
        );
    }

    /**
     * 根据城市和省份名称获取城市24小时天气信息
     * @param cityIds 城市id集合
     * @param getCityIdFunc 获取城市代码的函数
     * @return 城市基本信息
     */
    public <T> List<T> getCityTwentyForHoursData(
            String tableName,
            List<String> cityIds,
            Class<T> clazz,
            TriFunction<String, String, Class<T>, T> getCityIdFunc,
            TriFunction<String, String, Class<T>, List<T>> multiQueryFunc
    ) {
        Object cityData = queryUtil.getCityData(
                tableName,
                cityIds,
                clazz,
                getCityIdFunc,
                multiQueryFunc
        );

        if (cityData == null) {
            return null;
        }

        return (List<T>) cityData;
    }
}
